package com.cn.hotel.servlet.back.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.CompanyContactModel;
import com.cn.hotel.service.ICompanyContactService;
import com.cn.hotel.service.impl.CompanyContactServiceImpl;
import com.cn.hotel.util.Upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/contactAdd")
public class CompanyContactAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        Upload.imgUpload(req);
        CompanyContactModel companyModel = new CompanyContactModel();
        companyModel.setCompanyName((String) req.getAttribute("companyName"));
        companyModel.setAdress((String) req.getAttribute("adress"));
        companyModel.setPhone((String) req.getAttribute("phone"));
        companyModel.setEmail((String) req.getAttribute("email"));
        companyModel.setFax((String) req.getAttribute("fax"));
        companyModel.setQrCode((String) req.getAttribute("qrCode"));
        ICompanyContactService iCompanyService = new CompanyContactServiceImpl();
        int result = iCompanyService.add(companyModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
